﻿Type=Activity
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Private ulv,ulvjq As UltimateListView
	Private pord As Panel
	Private lstData,lstData2 As List
	Private isloading As Boolean=False
	Private isloadcompleted As Boolean=False
	Private pc As PayCls
	Private avp As AHViewPager
	Private avpc As AHPageContainer
	Private vpt As AHViewPagerFixedTabs
	Private pjqord As Panel
	Private ptab As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("layorderlist")
	initviews
End Sub
Sub initviews
	ulv.Initialize(comm.N_ULVMEMCACHE,comm.N_ULVDISKCACHE,comm.S_ULVCACHEDIR,"ulv")
	ulvjq.Initialize(comm.N_ULVMEMCACHE,comm.N_ULVDISKCACHE,comm.S_ULVCACHEDIR,"ulvj")
	ulv.Color=Colors.White
	ulvjq.Color=Colors.White
	pord.AddView(ulv,0,0,pord.Width,pord.Height)
	pjqord.AddView(ulvjq,0,0,pjqord.Width,pjqord.Height)
	Dim nh As Int=160dip
	pc.Initialize(Null)
	ulv.AddLayout("ord","ulv_LayoutCreator","ulv_ContentFiller",nh,True)
	ulvjq.AddLayout("ord","ulvjq_LayoutCreator","ulvjq_ContentFiller",nh,True)
	reqOrdLst
	lstData.Initialize
	lstData2.Initialize
	avpc.Initialize
	pord.RemoveView
	pjqord.RemoveView
	avpc.AddPage(pord,"课程订单")
	avpc.AddPage(pjqord,"锦旗订单")
	avp.PageContainer=avpc
	vpt.Initialize(avp)
	vpt.TextColor=Colors.Black
	ptab.AddView(vpt,0,0,100%x,ptab.Height)
End Sub
Sub avp_PageChanged (Position As Int)
	Select Position
	Case 0
		reqOrdLst
	Case 1
		reqJqLst
	End Select
End Sub
Private Sub reqOrdLst
	comm.showProgress("正在请求订单列表")
	ParseHelper.doGetReq(Me,"reqordlst",comm.getApi(comm.apiIdx.REQORDLST),Array As String("size","100"))
'	ParseHelper.doGetReq(Me,"reqordlst","http://192.168.1.3/t.php",Array As String("size","100"))
'	ParseHelper.doGetReq(Me,"reqordlst","http://kpjj.xjwanwei.com/t.php",Array As String("size","100"))
End Sub
Private Sub reqJqLst
	comm.showProgress("正在请求锦旗订单列表")
	ParseHelper.doGetReq(Me,"reqjqlst",comm.getApi(comm.apiIdx.REQJQLST),Null)
End Sub
Private Sub parseJinqiLst(str As String)
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject 
	Dim data As List = root.Get("data") 
	Dim i As Int=0
	lstData2.Clear
	ulvjq.ClearContent
	For Each coldata As Map In data 
	    Dim image As String = coldata.Get("image") 
	    Dim finished_time As String = coldata.Get("finished_time") 
	    Dim is_app As String = coldata.Get("is_app") 
	    Dim banner_id As String = coldata.Get("banner_id") 
	    Dim fukuan_type As String = coldata.Get("fukuan_type") 
	    Dim sex As String = coldata.Get("sex") 
	    Dim buyer_name As String = coldata.Get("buyer_name") 
	    Dim order_money As String = coldata.Get("order_money") 
	    Dim remark As String = coldata.Get("remark") 
	    Dim usertel As String = coldata.Get("usertel") 
	    Dim banner_name As String = coldata.Get("banner_name") 
	    Dim buyer_id As String = coldata.Get("buyer_id") 
	    Dim receive_id As String = coldata.Get("receive_id") 
	    Dim pay_time As String = coldata.Get("pay_time") 
	    Dim into_money As String = coldata.Get("into_money") 
	    Dim juname As String = coldata.Get("juname") 
	    Dim buyer_mobile As String = coldata.Get("buyer_mobile") 
	    Dim receive_name As String = coldata.Get("receive_name") 
	    Dim jutel As String = coldata.Get("jutel") 
	    Dim order_id As String = coldata.Get("order_id") 
	    Dim add_time As String = coldata.Get("add_time") 
	    Dim order_sn As String = coldata.Get("order_sn") 
	    Dim username As String = coldata.Get("username") 
	    Dim status As String = coldata.Get("status") 
		Dim jqi As JqOrderItem
		jqi.Initialize
		jqi.seller.Initialize
		jqi.seller.headimg=comm.combinPic(image)
		jqi.itemname=remark
		jqi.ordersn=order_sn
		jqi.price=order_money
		jqi.seller.nickname=buyer_name
		jqi.ordTime=add_time
		jqi.ordstatus=status
		jqi.ordid=order_id
		lstData2.Add(jqi)
		ulvjq.AddItem("ord",i)
		i=i+1
	Next 
	Dim status As String = root.Get("status") 

End Sub
Private Sub parseOrdLst(str As String)
	isloading=False
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject 
	Dim data As List = root.Get("data") 
	lstData.Clear
	ulv.ClearContent
	If data.IsInitialized=False Or data.Size=0 Then
		isloadcompleted=True
		Return
	End If
	Dim i As Int=0
	For Each coldata As Map In data 
	    Dim seller_kechen_id As String = coldata.Get("seller_kechen_id") 
	    Dim buyer_name As String = coldata.Get("buyer_name") 
	    Dim order_money As String = coldata.Get("order_money") 
	    Dim keshi As String = coldata.Get("keshi") 
	    Dim usertel As String = coldata.Get("usertel") 
	    Dim seller_mobile As String = coldata.Get("seller_mobile") 
	    Dim buyer_id As String = coldata.Get("buyer_id") 
	    Dim kechen_type As String = coldata.Get("kechen_type") 
	    Dim into_money As String = coldata.Get("into_money") 
	    Dim shiduan_list As List = coldata.Get("shiduan_list") 
'	    For Each colshiduan_list As Map In shiduan_list 
'	        Dim seller_kechen_id As String = colshiduan_list.Get("seller_kechen_id") 
'	        Dim sd_start_time As String = colshiduan_list.Get("sd_start_time") 
'	        Dim finished_time As String = colshiduan_list.Get("finished_time") 
'	        Dim tuikuan_time As String = colshiduan_list.Get("tuikuan_time") 
'	        Dim buyer_id As String = colshiduan_list.Get("buyer_id") 
'	        Dim sd_mode As String = colshiduan_list.Get("sd_mode") 
'	        Dim sd_hour As String = colshiduan_list.Get("sd_hour") 
'	        Dim kong As String = colshiduan_list.Get("kong") 
'	        Dim trd_id As String = colshiduan_list.Get("trd_id") 
'	        Dim sd_money As String = colshiduan_list.Get("sd_money") 
'	        Dim sd_end_time As String = colshiduan_list.Get("sd_end_time") 
'	        Dim riqi As String = colshiduan_list.Get("riqi") 
'	        Dim comment_content As String = colshiduan_list.Get("comment_content") 
'	        Dim id As String = colshiduan_list.Get("id") 
'	        Dim add_time As String = colshiduan_list.Get("add_time") 
'	        Dim order_sn As String = colshiduan_list.Get("order_sn") 
'	        Dim seller_id As String = colshiduan_list.Get("seller_id") 
'	        Dim status As String = colshiduan_list.Get("status") 
'	    Next 
	    Dim juname As String = coldata.Get("juname") 
	    Dim buyer_mobile As String = coldata.Get("buyer_mobile") 
	    Dim seller_name As String = coldata.Get("seller_name") 
	    Dim order_type As String = coldata.Get("order_type") 
	    Dim seller_id As String = coldata.Get("seller_id") 
	    Dim image As String = coldata.Get("image") 
	    Dim finished_time As String = coldata.Get("finished_time") 
	    Dim is_app As String = coldata.Get("is_app") 
	    Dim fukuan_type As String = coldata.Get("fukuan_type") 
	    Dim kc_title As String = coldata.Get("kc_title") 
	    Dim sex As String = coldata.Get("sex") 
	    Dim pay_time As String = coldata.Get("pay_time") 
	    Dim jutel As String = coldata.Get("jutel") 
	    Dim order_id As String = coldata.Get("order_id") 
	    Dim add_time As String = coldata.Get("add_time") 
	    Dim order_sn As String = coldata.Get("order_sn") 
	    Dim username As String = coldata.Get("username") 
	    Dim status As String = coldata.Get("status") 
		Dim oti As OrderItem
		oti.Initialize
		oti.price=order_money
		oti.seller.Initialize
		oti.seller.headimg=comm.combinPic(image)
		oti.seller.ID=seller_id
		oti.seller.nickname=seller_name
		oti.ordTime=add_time
		oti.itemname=kc_title
		oti.ordstatus=status
		oti.ordersn=order_sn
		oti.ordid=seller_kechen_id ' 这个用来发表评价时候用的
		lstData.Add(oti)
		ulv.AddItem("ord",i)
		i=i+1
	Next 
	Dim status As String = root.Get("status") 
	ulv.RefreshContent
End Sub
Sub JobDone(thj As HttpJob)
	ProgressDialogHide
	If thj.Success Then
		Dim str As String=thj.GetString
		Dim nr As netRes=ParseHelper.getStatusData(str)
		Log(str)
		Select thj.JobName
		Case "reqjqlst"
			If nr.nCode=200 Then
				parseJinqiLst(str)
			Else
				comm.TL("错误:"&nr.sData)
			End If
		Case "reqordlst"
			If nr.nCode=200 Then
				parseOrdLst(str)
			Else
				comm.TL("错误:"&nr.sData)
			End If
		Case "postrate"
			If nr.nCode=200 Then
				comm.TL("评价提交成功")
			Else
				comm.TL("错误:"&nr.sData)
			End If
		End Select
		
	Else
		comm.TL("网络错误:"&thj.JobName&thj.ErrorMessage)
	End If
	thj.Release
End Sub
Sub ulv_LayoutCreator(LayoutName As String, LayoutPanel As Panel)
	If LayoutName.EqualsIgnoreCase("ord") Then
		LayoutPanel.LoadLayout("itemkcorder")
	End If
End Sub
Sub ulv_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	Dim p As Panel=LayoutPanel.GetView(0)
	Private btnpay As Button=p.GetView(5)
	Private btnrate As Button=p.GetView(6)
	Private itemkcname As Label=p.GetView(1)
	Private itemorderdate As Label=p.GetView(4)
	Private itempaymentstatus As Label=p.GetView(3)
	Private itemprice As Label=p.GetView(2)
	'Private itemteacherheaderriv As RoundedImageView
	Private riv As RIV
	Private itemteachername As Label=p.GetView(0)
	p=p.GetView(8)
	riv=p.GetView(0) '需要从panel中取出来才是riv
	Dim oti As OrderItem=lstData.Get(ItemID)
	If oti.seller.headimg.Length>1 Then
		comm.loadimg(oti.seller.headimg,riv)
	Else
		comm.loadimg(comm.S_TESTTEACHERHEADER,riv)
	End If
	'Log("pos="&ItemID&" "&oti.ordstatus)
	itemteachername.Text=oti.seller.nickname
	itemkcname.Text=oti.itemname
	itemorderdate.Text=oti.ordTime
	itempaymentstatus.Text=oti.ordstatus
	itemprice.Text=$"$1.1{oti.price}"$
	btnpay.Tag=ItemID
	btnpay.Visible=True
	Select oti.ordstatus
	Case "已提交"
		btnpay.Text="支付"
		btnpay.Background=getpaycd
	Case "已付款"
		btnpay.Text="退款"
		btnpay.Background=gettkcd
	Case "已排课"
		btnpay.Text="退款"
		btnpay.Background=gettkcd
	Case "已完成"
		btnpay.Text="评价"
		btnpay.Background=gettkcd
	Case Else
		btnpay.Visible=False
	End Select
	btnpay.Invalidate
End Sub
Sub ulvjq_LayoutCreator(LayoutName As String, LayoutPanel As Panel)
	If LayoutName.EqualsIgnoreCase("ord") Then
		LayoutPanel.LoadLayout("itemkcorder")
	End If
End Sub
Sub ulvjq_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
	Dim p As Panel=LayoutPanel.GetView(0)
	Private btnpay As Button=p.GetView(5)
	Private btnrate As Button=p.GetView(6)
	Private itemkcname As Label=p.GetView(1)
	Private itemorderdate As Label=p.GetView(4)
	Private itempaymentstatus As Label=p.GetView(3)
	Private itemprice As Label=p.GetView(2)
	'Private itemteacherheaderriv As RoundedImageView
	Private riv As RIV
	Private itemteachername As Label=p.GetView(0)
	p=p.GetView(8)
	riv=p.GetView(0) '需要从panel中取出来才是riv
	Dim oti As OrderItem=lstData.Get(ItemID)
	If oti.seller.headimg.Length>1 Then
		comm.loadimg(oti.seller.headimg,riv)
	Else
		comm.loadimg(comm.S_TESTTEACHERHEADER,riv)
	End If
	'Log("pos="&ItemID&" "&oti.ordstatus)
	itemteachername.Text=oti.seller.nickname
	itemkcname.Text=oti.itemname
	itemorderdate.Text=oti.ordTime
	itempaymentstatus.Text=oti.ordstatus
	itemprice.Text=$"$1.1{oti.price}"$
	btnpay.Tag=ItemID
	Select oti.ordstatus
	Case "已提交"
		btnpay.Text="支付"
		btnpay.Background=getpaycd
	Case "已付款"
		btnpay.Text="退款"
		btnpay.Background=gettkcd
	Case "已排课"
		btnpay.Text="退款"
		btnpay.Background=gettkcd
	Case "已完成"
		btnpay.Text="评价"
		btnpay.Background=gettkcd
	Case Else
		btnpay.Visible=False
	End Select
	btnpay.Invalidate
End Sub
Private Sub getpaycd As ColorDrawable
	Dim cd As ColorDrawable
	cd.Initialize(0xffFF6A00,5)
	Return cd
End Sub
Private Sub gettkcd As ColorDrawable
	Dim cd As ColorDrawable
	cd.Initialize(0xff009688,5)
	Return cd
End Sub
'Sub ulv_Scrolled(FirstVisibleItem As Int, VisibleItemCount As Int, TotalItemCount As Int, IsAtTop As Boolean, IsAtBottom As Boolean)
'	If IsAtBottom And isloading=False And isloadcompleted=False Then
'		addmore
'	End If
'End Sub
'Sub addmore
'	isloading=True
'End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub ivback_Click
	Activity.Finish
End Sub

Sub btnrate_Click
	Dim v As View=Sender
	ToastMessageShow("rate clicked idx:"&v.Tag,False)
End Sub
Sub ulv_ItemClick(ItemID As Long, Position As Int, ClickedPanel As Panel)
	Dim it As OrderItem=lstData.Get(Position)
	g_store.put("odid",it.ordersn)
	StartActivity(actOrderDetail)
	Log(it.ordersn)	
End Sub

Sub btnpay_Click
	Dim v As Button=Sender
	'ToastMessageShow("pay clicked idx:"&v.Tag,False)
	Dim idx As Int=v.Tag
	Dim kci As OrderItem=lstData.Get(idx)
	Select v.Text
	Case "支付"
		Dim pid As payItem
		pid.Initialize
		pid.pid=kci.ordersn
		pid.money=kci.price
		g_store.put("pid",pid)
		StartActivity(actSelectPayMethod)
	Case "退款"
		CallSubDelayed3(actOrderDetail,"reqrefundall",kci.ordersn,"0")
	Case "评价"
		Dim oti As OrderItem=lstData.Get(idx)
		showdialograte(oti)
		'comm.TL("未完成")
	End Select
End Sub
Sub showdialograte(oti As OrderItem)
	Dim pbody As Panel
	Dim bd As BetterDialogs
	pbody=comm.CreateCustomPanel(Activity,80%x,45%y)
	pbody.LoadLayout("dlgrate")
	Dim dlgParams As BD_CustomDlgParams
	Dim edt As EditText=pbody.GetView(0)
	Dim p As Panel=pbody.GetView(1)
	Dim c1,c2,c3 As RadioButton
	c1=p.GetView(0)
	c2=p.GetView(1)
	c3=p.GetView(2)
	comm.setFA(c1,"fa-heart","好评")
	comm.setFA(c2,"fa-heart","中评")
	comm.setFA(c3,"fa-heart","差评")
	dlgParams.Initialize
	dlgParams.DialogBody = pbody
	dlgParams.BodyWidth = pbody.Width
	dlgParams.BodyHeight = 180dip
	dlgParams.PositiveButton="确定"
	dlgParams.NegativeButton="取消"
	'dlgParams.Duration = 30 '自动关闭
	Dim DR As Int = bd.CustomDialog(dlgParams, "CD1")
	If DR==DialogResponse.POSITIVE Then
		Dim ratecontents As String=edt.Text.Trim
		Dim ratetype As Int
		If c1.Checked Then 
			ratetype=1
		Else if c2.Checked Then
			ratetype=2
		Else
			ratetype=3
		End If
		reqRate(oti.seller.ID,oti.ordersn,oti.ordid,ratecontents,ratetype)
	End If
End Sub
'kc_id =kci.ordid
Sub reqRate(js_id As String,ordsn As String,kc_id As String,content As String,comment_type As Int)
	comm.showProgress("正在提交评价信息")
	ParseHelper.doPostReqArr(Me,"postrate",comm.getApi(comm.apiIdx.POSTRATE),Array As String("zp_id",0,"suoshu_id",0,"js_id",js_id,"kc_id",kc_id,"ziorder",ordsn,"is_teach",0,"content",content,"comment_type",comment_type),"")
End Sub
